package com.gui;

import com.extractor.DataExtractor;

import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;

/**
 * Created by IntelliJ IDEA.
 * User: SeedMiner
 * Date: Jun 29, 2010
 * Time: 7:24:07 AM
 * To change this template use File | Settings | File Templates.
 */
public class Mas {
    public JPanel panel1;
    private JTextField textField1;
    private JPanel panel2;
    public JTextArea colums;
    private JPanel panel3;
    private JButton calculateRatiosAndSaveButton;
    private JButton button1;
    private JLabel status;
    public JPanel userInputMainPanel;
    public JPanel userInputFabricType;
    private JTextField textField3;
    private JButton calculateRatios;
    JFileChooser fc = new JFileChooser();
    String csvFilePath;
    public DataExtractor de;

    public Mas() {
        button1.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                //Handle open button action.
                int returnVal = fc.showOpenDialog(panel1);

                if (returnVal == JFileChooser.APPROVE_OPTION) {
                    File file = fc.getSelectedFile();
                    csvFilePath = file.getAbsolutePath();
                    //This is where a real application would open the file.
                    //System.out.println("Opening: " + file.getName() + " " + file.getAbsolutePath());
                    textField1.setText(file.getAbsolutePath());
                } else {
                    System.out.println("Open command cancelled by user.");
                }
            }
        });
        calculateRatiosAndSaveButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                if (!("").equals(textField1.getText())) {
                    de.ExtractData(textField1.getText());
                }
            }
        });
        calculateRatios.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                //de.createFabricCostingValueTable();
                de.calculateRatiosAndSaveOutput();
            }
        });
    }
}
